{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# This notebook assumes to be running from your FireCARES VM (eg. python manage.py shell_plus --notebook --no-browser)\n",
    "\n",
    "import sys\n",
    "import os\n",
    "import time\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "sys.path.insert(0, os.path.realpath('..'))\n",
    "import folium\n",
    "import django\n",
    "import sqlite3\n",
    "django.setup()\n",
    "from django.db import connections\n",
    "from pretty import pprint\n",
    "from firecares.firestation.models import (FireDepartment, FireStation, NFIRSStatistic, FireDepartmentRiskModels,\n",
    "                                          PopulationClassQuartile)\n",
    "from fire_risk.models import DIST, DISTMediumHazard, DISTHighHazard\n",
    "from fire_risk.models.DIST.providers.ahs import ahs_building_areas\n",
    "from fire_risk.models.DIST.providers.iaff import response_time_distributions\n",
    "from django.db.models import Avg, Max, Min, Q\n",
    "from django.contrib.gis.geos import GEOSGeometry\n",
    "from IPython.display import display\n",
    "from firecares.utils import lenient_summation, dictfetchall\n",
    "from firecares.tasks.update import (calculate_department_census_geom, calculate_story_distribution,\n",
    "                                    calculate_structure_counts, update_performance_score, update_nfirs_counts,\n",
    "                                    dist_model_for_hazard_level)\n",
    "pd.set_option(\"display.max_rows\", 2000)\n",
    "pd.set_option(\"display.max_columns\", 100)\n",
    "\n",
    "def display_geom(geom):\n",
    "    _map = folium.Map(location=[geom.centroid.y, geom.centroid.x],\n",
    "                      tiles='Stamen Toner')\n",
    "    _map.choropleth(geo_str=geom.geojson, line_weight=0, fill_opacity=0.2, fill_color='green')\n",
    "    ll = geom.extent[1::-1]\n",
    "    ur = geom.extent[3:1:-1]\n",
    "    _map.fit_bounds([ll, ur])\n",
    "\n",
    "    return _map\n",
    "\n",
    "# Philadephia-specific\n",
    "fd = FireDepartment.objects.get(id=91907)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
